<?php
/***************************************************************************
 * 
 * Copyright (c) 2010 , Inc. All Rights Reserved
 * $Id$:MCUtil.php,2010/05/20 13:35:41 
 * 
 **************************************************************************/
 
 
 
/**
 * @file LibUtil.php
 * @author huqingping
 * @date 2010/05/20 13:35:41
 * @version 1.0 
 * @brief 
 *  
 **/

final class LibUtil
{
	static $modules = array();
	static function load($module,$params=array())
	{
		$module = ucfirst($module);
		if (isset(self::$modules[$module])) {
			return self::$modules[$module];
		}
		if (!class_exists($module)) {
			if (strpos($module,'..') !== false) {
				throw new Exception($module,'LibUtil.errpath');
			}
			require_once dirname(__FILE__).'/'.$module.'.php'; 
			if (!class_exists($module)) {
				throw new Exception('LibUtil.errclass');
			}
		}
//		$mod = new $module();
		$reflect=new ReflectionClass($module);
		if(empty($params)) {
			$mod=$reflect->newInstance();
		}
		else{
			$mod=$reflect->newInstanceArgs($params);
		}
		if (!empty($mod->cacheable)) {
			self::$modules[$module] = $mod;	
		}
		return $mod;
	}
}






/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */
